package cn.oracle.eshop.cart.dao.impl;

import cn.oracle.eshop.cart.dao.ShoppingCartDAO;
import cn.oracle.eshop.cart.domain.ShoppingCartDO;
import cn.oracle.eshop.cart.mapper.ShoppingCartMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/**购物车管理模块的DAO组件
 * @author wyh
 * @ClassName ShoppingCartDAOImpl
 * @date 2022/3/28 /21:11
 */
@Slf4j
@Repository
public class ShoppingCartDAOImpl implements ShoppingCartDAO {
    /***
     * 购物车管理模块的mapper组件
    */
    @Autowired
    private ShoppingCartMapper shoppingCartMapper;
    /***
     *  根据用户ID查询购物车
     * @author wyh
     * @date 2022/3/28
     * @param userAccountId
     * @return cn.oracle.eshop.cart.domain.ShoppingCartDO
    */
    @Override
    public ShoppingCartDO getShoppingCartByUserAccountId(Long userAccountId) {
        try {
            return shoppingCartMapper.getShoppingCartByUserAccountId(userAccountId);
        } catch (Exception e) {
           log.error("error：{}",e);
        }
        return new ShoppingCartDO();
    }
/***
 *  新增购物车
 * @author wyh
 * @date 2022/3/28
 * @param shoppingCartDO  购物车DO对象
 * @return void
*/
    @Override
    public Long saveShoppingCart(ShoppingCartDO shoppingCartDO) {
        try {
            shoppingCartMapper.saveShoppingCart(shoppingCartDO);
        } catch (Exception e) {
          log.error("error:{}",e);
            return null;
        }

        return  shoppingCartDO.getId();
    }
}
